package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.response.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.entity.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.entity.vo.BorrowerDetailVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-05-26
 */
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Resource
    BorrowerService borrowerService;
    @ApiOperation("提交借款额度审批结果")
    @PostMapping("approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.borrowerApproval(borrowerApprovalVO);
        return R.ok();
    }
    @ApiOperation("根据id查询借款人详情")
    @GetMapping("{id}")
    public R getById(@PathVariable("id")String id){
        BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetailById(id);
        return R.ok().data("item",borrowerDetailVO);
    }

    @ApiOperation("条件查询借款人分页数据")
    @GetMapping("list/{pageNum}/{pageSize}")
    public R list(@PathVariable("pageNum")Integer pageNum,
                  @PathVariable("pageSize")Integer pageSize,
                  // 以后前端提交的复杂的参数也可以通过一个字符串接收： key=k1:v1-k2:v2-k3:v3
                  String key){
        // page的泛型 使用前端需要展示数据对应的类型
        //  业务层查询的代码 可以将查询到的数据转为Page的泛型需要类型的数据
        Page<Borrower> page =  borrowerService.getBorrowerPage(pageNum,pageSize,key);
        return R.ok().data("page",page);
    }

}

